/**
 * Created by superman on 17/2/16.
 */
import Vuex from 'vuex'
import Vue from 'vue'
import * as types from './types'

Vue.use(Vuex);
export default new Vuex.Store({
    state: {
        username: '',
        token: null,
        title: '',
        isLogin:false,
        routeName:'',
        routeDesc:'',
        firstTitle:'',
        lastTitle:'',
        credentials:'',
        houseInfo:[],
        currentHouse:null
    },
    mutations: {
        [types.LOGIN]: (state, data) => {
            state.credentials = data;
        },
        [types.HOUSEINFO]: (state, data) => {
            state.houseInfo = data;
        },
        [types.CURRENTHOUSE]: (state, data) => {
            state.currentHouse = data;
        },
        [types.CHANGEROUTE]: (state,data) => {
            state.routeName = data;
        },
        [types.CHANGEROUTEDESC]: (state,data) => {
            state.firstTitle = data.firstTitle;
            state.lastTitle = data.lastTitle;
        },
        [types.LOGOUT]: (state) => {
            localStorage.removeItem('token');
            localStorage.removeItem('username');
            state.token = null;
        },
        [types.TITLE]: (state, data) => {
            state.title = data;
        },
        [types.ISLOGINPAGE]: (state) => {
            state.isLogin = true;
        },
        [types.NOTLOGINPAGE]: (state) => {
            state.isLogin = false;
        }
    },
    getters : {
        getIslogin: function (state) {
            return state.isLogin;
        },
        getUsername: function (state) {
            return state.username;
        },
        getRouteName: function (state) {
            return state.routeName;
        },
        getRouteDesc: function (state) {
            return {firstTitle:state.firstTitle,lastTitle:state.lastTitle} ;
        },
        getHouseInfo: function (state) {
            return state.houseInfo;
        },
        getCurrentHouse: function (state) {
            return state.currentHouse;
        },
        getCredentials: function (state) {
            return state.credentials;
        },

    }
})